/**
* @description: 201. 数字范围按位与
* @author hewei
* @date 2022/7/28 15:11
* @version 1.0
*/

public class RangeBitwiseAnd {

    public int rangeBitwiseAnd(int left, int right) {
        int count = 0;
        while (left != right) {
            left >>= 1;
            right >>= 1;
            ++count;
        }
        return left << count;
    }

    public int rangeBitwiseAnd1(int left, int right) {
        while (right > left) {
            right &= (right - 1);
        }
        return right;
    }
}
